Skip to content

fix: reject unknown properties on session() and charge() at compile time#203

Merged
brendanjryan merged 2 commits intomainfrom
fix/no-extra-keys
Mar 27, 2026
Merged

fix: reject unknown properties on session() and charge() at compile time#203
brendanjryan merged 2 commits intomainfrom
fix/no-extra-keys

Conversation

@brendanjryan
Copy link
Copy Markdown
Collaborator

@brendanjryan brendanjryan commented Mar 19, 2026

Problem

Makes interface for kwargs on mppx core types safer

Solution

Add a NoExtraKeys<T, Shape> utility type that maps any key in T not present in Shape to never, and apply it to session() and charge() via overload signatures.

// Before: silently accepted
tempo.session({ stream: { poll: true }, ... })

// After: compile error
// Type '{ poll: true; }' is not assignable to type 'never'
tempo.session({ stream: { poll: true }, ... })

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/mppx@203

commit: 27dee9a

@brendanjryan brendanjryan force-pushed the fix/no-extra-keys branch 2 times, most recently from ba24a01 to cb52419 Compare March 19, 2026 15:27
@brendanjryan brendanjryan requested review from jxom and tmm March 27, 2026 20:46
@brendanjryan
Copy link
Copy Markdown
Collaborator Author

cc @tmm @jxom if there is a cooler way to do this in ts

'mppx': patch
---

Added `NoExtraKeys` compile-time guard to `tempo.session()` and `tempo.charge()`. Unknown properties (e.g. `stream` instead of `sse`) now cause a type error instead of being silently accepted.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Added `NoExtraKeys` compile-time guard to `tempo.session()` and `tempo.charge()`. Unknown properties (e.g. `stream` instead of `sse`) now cause a type error instead of being silently accepted.
Added compile-time guard to `tempo.session()` and `tempo.charge()`. Unknown properties (e.g. `stream` instead of `sse`) now cause a type error instead of being silently accepted.

Comment on lines 85 to 93
export function session<const parameters extends session.Parameters>(
p?: NoExtraKeys<parameters, session.Parameters>,
): Method.Server<
typeof Methods.session,
session.DeriveDefaults<parameters>,
parameters['sse'] extends false | undefined ? undefined : Transport.Sse
>
/** @internal */
export function session<const parameters extends session.Parameters>(p?: parameters) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the overload, might be worth trying a Union version of NoExtraKeys if you haven't already

brendanjryan and others added 2 commits March 27, 2026 15:35
Add NoExtraKeys utility type and apply it via overload signatures to
tempo.session() and tempo.charge(). This catches typos like
`stream: { poll: true }` instead of `sse: { poll: true }` that
previously slipped through because generic `extends` constraints
bypass excess property checking.

Fixes the class of bug from PR #159.
@brendanjryan brendanjryan merged commit 3bc8657 into main Mar 27, 2026
8 of 10 checks passed
@brendanjryan brendanjryan deleted the fix/no-extra-keys branch March 27, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants